const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
import {bindName,UrlCode} from '../../api/cloud.js';
Page({
  data: {
    nbFrontColor: '#000000',
    nbBackgroundColor: '#ffffff',
    avatarUrl:wx.getStorageSync('avatarUrl'),
	nickName:wx.getStorageSync('nickName'),
    saoma:null,
    url:'regjoihkjfbnkj',
	avatarUrl2: defaultAvatarUrl,
	hasUserInfo:true
  },
  onLoad() {
    if(wx.getStorageSync('nickName')){
		  this.setData({
			  avatarUrl:wx.getStorageSync('avatarUrl'),
			  nickName:wx.getStorageSync('nickName'),
				hasUserInfo: false,
		 })
	  }else{
			this.setData({
						  avatarUrl:defaultAvatarUrl,
						  nickName:'获取头像', 
			})
			
		 }
    this.setData({
      nbTitle: '',
      nbLoading:false,
      nbFrontColor: '#ffffff',
      nbBackgroundColor: '#0081D8',
    })
	
  },
  onChooseAvatar(e) {
	  console.log(e.detail)
      const { avatarUrl } = e.detail 
      this.setData({
        avatarUrl,
      })
    },
  /**
   * 获取授权头像
   */
  getHeadimg(){
	 wx.getUserProfile({
	       desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
	       success: (res) => {
			   
			 this.setData({
			 			  avatarUrl:res.userInfo.avatarUrl,
			 			  nickName:res.userInfo.nickName,
			 })
			 wx.setStorageSync('nickName',res.userInfo.nickName);
			 wx.setStorageSync('avatarUrl',res.userInfo.avatarUrl);
			 
			 bindName({
				nickname:res.userInfo.nickName,
				headimgurl:res.userInfo.avatarUrl
			 }).then(rs=>{
				wx.showToast({
				  title: rs.msg,
				  icon: 'success'
				}) 
			 })
	       }
	     }) 
  },
  meimage(){
    wx.navigateTo({
      url: '/pages/image/image'
    })
  },
  update(){
    wx.navigateTo({
      url: '/pages/update/update'
    })
  },
  /**
   * @param {Object} event
   */
  navTo(event) {
    
    wx.navigateTo({
      url: '/pages/zhanghao/zhanghao'
    })
  },
  saoma()
  {
    var _this = this;
    console.log('123');
    wx.scanCode({
      
      onlyFromCamera: true,
      success (res) {
        console.log(res.result);
        // this.setData({
        //   saoma: res.result,
        //  });
        _this.setData({
          saoma: res.result,
         });
      }
    }) 
  },
  about(){
    wx.requestSubscribeMessage({
      tmplIds: ['lzKn7VikFKa6Onv-8Yyhw1j3aWcNSnGbSfn0KrKjg_s',
                'KE3KEqJr8homU9Zr3C-aUCB2_7IpStOps_zrBrlDfb0',
              'KfncaHyF0YkzHlSmuDy1uqEb_VFtAT37Yk6J9-kn2Ac'],//这里填写模板id
      success(res) {
      },
       fail:err=>{
         console.log("err---",err)
       }
    })
  },
  updateUrl(e){
      let openid = wx.getStorageSync('openid')
      if(!openid){
      wx.showToast({
        title: '没有登录'
      })
      return 
      }
      wx.showLoading({
        title: '获取中',
      })
      UrlCode().then(res=>{
        wx.hideLoading()
        let url = res.data
        wx.setClipboardData({
          data: url,
          success: function (res) {
            wx.getClipboardData({
              success: function (res) {
                wx.showToast({
                  title: '复制成功'
                })
              }
            })
          }
        })
      }).catch(err=>{
        wx.hideLoading()
      })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
	wx.startPullDownRefresh({
		  success:function(res){
			  console.log('下拉了')
			  wx.stopPullDownRefresh()
		  }
	})
	wx.stopPullDownRefresh()
	// console.log('下拉了www')
  },
  handleContact (e) {
    console.log(e.detail.path)
    console.log(e.detail.query)
}
})